/* Copyright 2010 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT c;pWARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * @author Jeremy Brown
 */

package org.sil.iso639_3;
import org.ethnologue.iso639_3.*;

public class LD /*Ethnologue Language Data*/
{
	//Language Scope
	public static final String INDIVIDUAL = "I";
	public static final String MACROLANGUAGE = "M";

	//Language Scope / Language Type
	public static final String SPECIAL = "S";

	//Language Type
	public static final String ANCIENT = "A";
	public static final String CONSTRUCTED = "C";
	public static final String EXTINCT = "E";
	public static final String HISTORICAL = "H";
	public static final String LIVING = "L";

	
	private String code; //ISO639-3 language code (3 letters, lower case)
	private String name; //ISO639-3 language name
	private String scope;
	private String languageType; //Current status 
	private String macrolanguageCode; //Code of macrolanguage for this language, if applicable
	private String part2BCode; //ISO639-2 Bibliographic code for this language, if applicable
	private String part2TCode; //ISO639-2 Terminology code for this language, if applicable
	private String part1Code; //ISO639-1 code for this language, if applicable
	private String[] names; //List of print names
	private String[] invertedNames; //List of invertedNames
	
	private boolean retrievedELD = false;
	private ELD eld = null; //Stores the ELD (Ethnologue Language Data) for this language code (if available). This is lazily resolved by the getELD() method.
	
	public LD(String code, String name, String scope, String languageType, String macrolanguageCode, String part2BCode, String part2TCode, String part1Code, String[] languageNames, String[] languageNamesInverted)
	{
		this.code=code;
		this.name=name;
		this.scope=scope;
		this.languageType=languageType;
		this.macrolanguageCode=macrolanguageCode;
		this.part2BCode=part2BCode;
		this.part2TCode=part2TCode;
		this.part1Code=part1Code;
		this.names=languageNames;
		this.invertedNames=languageNamesInverted;
	}
	
	public void setCode(String code){this.code = code;}
	public void setName(String name){this.name = name;}
	public void setScope(String scope){this.scope = scope;}
	public void setLanguageType(String languageType){this.languageType = languageType;}
	public void setMacrolanguageCode(String macrolanguageCode){this.macrolanguageCode = macrolanguageCode;}
	public void setPart2BCode(String part2BCode){this.part2BCode = part2BCode;}
	public void setPart2TCode(String part2TCode){this.part2TCode = part2TCode;}
	public void setPart1Code(String part1Code){this.part2TCode = part1Code;}
	public void setNames(String[] names){this.names = names;}
	public void setInvertedNames(String[] invertedNames){this.invertedNames = invertedNames;}
	
	public String getCode(){return code;}
	public String getName(){return name;}
	public String getScope(){return scope;}
	public String getLanguageType(){return languageType;}
	public String getMacrolanguageCode(){return macrolanguageCode;}
	public String getPart2BCode(){return part2BCode;}
	public String getPart2TCode(){return part2TCode;}
	public String getPart1Code(){return part1Code;}
	public String[] getNames(){return names;}
	public String[] getInvertedNames(){return invertedNames;}

	
	public String getDisplayLanguageType()
	{
		return LD.getDisplayLanguageType(languageType);
	}
	public static String getDisplayLanguageType(String s)
	{
		if(s.equals(ANCIENT)){return "Ancient";}
		if(s.equals(CONSTRUCTED)){return "Constructed";}
		if(s.equals(EXTINCT)){return "Extinct";}
		if(s.equals(HISTORICAL)){return "Historical";}
		if(s.equals(LIVING)){return "Living";}
		if(s.equals(SPECIAL)){return "Special";}
		return s;
	}
	
	public String getDisplayScope()
	{
		return LD.getDisplayScope(scope);
	}
	public static String getDisplayScope(String t)
	{
		if(t.equals(INDIVIDUAL)){return "Individual";}
		if(t.equals(MACROLANGUAGE)){return "Macrolanguage";}
		if(t.equals(SPECIAL)){return "Special";}
		return t;
	}
	
	public ELD getELD()
	{
		if(!retrievedELD)
		{
			eld = ELanguageByCode.get(code);
			retrievedELD = true;
		}
		return eld;
	}

	
	public String toString()
	{
		return code + "__" + name;
	}
}